#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int d, s, b;
int t;
char a[9][6505];
string check() {
  rep(j, 1, s * b) {
    int res = 0;
    set<int> st;
    rep(i, 1, d) {
      if (a[i][j] == 'x')
        st.insert(i);
      else
        res ^= a[i][j] - '0';
    }
    if (st.size() > 1)
      return "";
    else if (st.size()) {
      int i = *st.begin();
      a[i][j] = t == res ? '0' : '1';
    } else {
      if (t != res) return "";
    }
  }
  string data;
  for (int j = 1, p = 1; j <= s * b; j += s, p = p % d + 1) {
    rep(i, 1, d) {
      if (i == p) continue;
      rep(k, 0, s - 1) { data.push_back(a[i][j + k]); }
    }
  }
  while (data.size() % 4) data.push_back('0');
  return data;
}
char hex(int x) {
  if (x <= 9)
    return '0' + x;
  else
    return 'A' + x - 10;
}
string decode(string& data) {
  string res;
  for (int i = 0; i < data.size(); i += 4) {
    int x = 0;
    rep(j, i, i + 3) x = x * 2 + data[j] - '0';
    res += hex(x);
  }
  return res;
}
void solve(int id) {
  cout << "Disk set " << id << " is ";
  string res = check();
  if (res.empty())
    cout << "invalid." << endl;
  else
    cout << "valid, contents are: " << decode(res) << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // freopen("1.txt", "r", stdin);
  // freopen("2.txt", "w", stdout);
  int id = 0;
  while (cin >> d && d != 0) {
    cin >> s >> b;
    char c;
    cin >> c;
    if (c == 'E')
      t = 0;
    else
      t = 1;
    rep(i, 1, d) rep(j, 1, s * b) cin >> a[i][j];
    solve(++id);
  }
  return 0;
}